package com.koron.standard.handler;

import cn.hutool.core.util.StrUtil;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.config.ThreadLocalContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 标准管理的所有请求在处理之前，设置数据源信息为_default
 * @author jzp
 * @since 2021/9/10
 */
public class UserInfoInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        EamUser eamUser = ThreadLocalContext.get();
        if (eamUser != null && StrUtil.isNotEmpty(eamUser.getCurrDs())) {
            eamUser.setCurrDs("_default");
        }
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
